package com.haochang.chunkvod.model.order;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *@author qintao
 *created at 2016/6/22 14:28
 * 活动详情
 */

public class FoodInfo implements Serializable
{
	private String id;
	private String name;
	private String combo_id;
	private int quantity;
	private int weight;
	private String unit;
	private String goods;
	private String type;
	private int orderNum = 0;
	private int defaultNum = 0;
	private int is_outposition;
	private int output_status = 0;
	private String d_id_key;
	private String d_id_value;
	private List<FoodDetailInfo> foodList = new ArrayList<FoodDetailInfo>();
	private boolean isExpand = false;
	private int is_present = 0;

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getCombo_id()
	{
		return combo_id;
	}

	public void setCombo_id(String combo_id)
	{
		this.combo_id = combo_id;
	}

	public int getQuantity()
	{
		return quantity;
	}

	public void setQuantity(int quantity)
	{
		this.quantity = quantity;
	}

	public int getWeight()
	{
		return weight;
	}

	public void setWeight(int weight)
	{
		this.weight = weight;
	}

	public String getGoods()
	{
		return goods;
	}

	public void setGoods(String goods)
	{
		this.goods = goods;
	}

	public String getType()
	{
		return type;
	}

	public void setType(String type)
	{
		this.type = type;
	}

	public String getUnit()
	{
		return unit;
	}

	public void setUnit(String unit)
	{
		this.unit = unit;
	}

	public int getOrderNum()
	{
		return orderNum;
	}

	public void setOrderNum(int orderNum)
	{
		this.orderNum = orderNum;
	}

	public List<FoodDetailInfo> getFoodList()
	{
		return foodList;
	}

	public void setFoodList(List<FoodDetailInfo> foodList)
	{
		this.foodList = foodList;
	}

	public int getIs_outposition()
	{
		return is_outposition;
	}

	public void setIs_outposition(int is_outposition)
	{
		this.is_outposition = is_outposition;
	}

	public int getOutput_status()
	{
		return output_status;
	}

	public void setOutput_status(int output_status)
	{
		this.output_status = output_status;
	}

	public String getD_id_key()
	{
		return d_id_key;
	}

	public void setD_id_key(String d_id_key)
	{
		this.d_id_key = d_id_key;
	}

	public String getD_id_value()
	{
		return d_id_value;
	}

	public void setD_id_value(String d_id_value)
	{
		this.d_id_value = d_id_value;
	}

	public int getDefaultNum()
	{
		return defaultNum;
	}

	public void setDefaultNum(int defaultNum)
	{
		this.defaultNum = defaultNum;
	}

	public boolean isExpand()
	{
		return isExpand;
	}

	public void setExpand(boolean expand)
	{
		isExpand = expand;
	}

	public int getIs_present()
	{
		return is_present;
	}

	public void setIs_present(int is_present)
	{
		this.is_present = is_present;
	}

	public FoodInfo(JSONObject jsonObject)
	{
		if (jsonObject != null)
		{
			this.name = jsonObject.optString("name");
			this.combo_id = jsonObject.optString("combo_id");
			this.quantity = jsonObject.optInt("quantity");
			this.weight = jsonObject.optInt("weight");
			this.type = jsonObject.optString("type");
			this.is_present = jsonObject.optInt("is_present");
			JSONArray jsonArray = jsonObject.optJSONArray("goods");
			if (jsonArray != null && jsonArray.length() > 0)
			{
				this.goods = jsonArray.toString();
				List<FoodDetailInfo> detailInfoList = new ArrayList<FoodDetailInfo>();
				try
				{
					JSONArray array = new JSONArray(this.goods);
					int defaultNum = 0;
					for (int j = 0; j < array.length(); j++)
					{
						FoodDetailInfo goodsDetailInfo = new FoodDetailInfo(array.getJSONObject(j));
						goodsDetailInfo.setCombo_id(this.combo_id);
						detailInfoList.add(goodsDetailInfo);
						defaultNum += goodsDetailInfo.getNumber();
					}
					this.defaultNum = defaultNum;
				} catch (JSONException e)
				{
					e.printStackTrace();
				}
				this.foodList = new ArrayList<FoodDetailInfo>();
				this.foodList.addAll(detailInfoList);
			}
			if (type.equals("master"))
			{
				this.orderNum = jsonObject.optInt("quantity");
			}
		}
	}

	public FoodInfo()
	{
	}

}
